package com.dailyblue.java;

import lombok.SneakyThrows;

import java.io.File;
import java.io.RandomAccessFile;

public class DemoB {
    @SneakyThrows
    public static void main(String[] args) {
        File file = new File("/Users/dailyblue/a/a.txt");
        RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
        randomAccessFile.seek(3); // Hello,world!
        randomAccessFile.writeBytes("1234");
        randomAccessFile.seek(0);
        byte[] bytes = new byte[100];
        // 实际读取长度
        int len = randomAccessFile.read(bytes);
        String str = new String(bytes, 0, len);
        System.out.println(str);
    }
}
